﻿using HBKY.Shop.Extensions.CoreBuilder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace HBKY.Shop.Extensions.Extensions
{
    public static class BuilderExt
    {
        /// <summary>
        /// 添加中间件
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static void AddServiceProvider(this IServiceCollection services, IConfiguration configuration)
        {
            ICoreServiceBuilder servicebuilder = new ServiceBuilder(services, configuration);
            servicebuilder.AddNlogLayoutRenderers();
            servicebuilder.AddMvcExtensions();
            servicebuilder.AddCache();
            servicebuilder.AddSqlSugar();
            servicebuilder.AddSwaggerGenerator();
            servicebuilder.AddLog();
            servicebuilder.AddAutoMapper();
            servicebuilder.AddCors();
            servicebuilder.AddTaskJob();
            servicebuilder.AddJwtAuth();
            servicebuilder.AddHttpContext();
            servicebuilder.AddHttpClient();
            servicebuilder.AddProducer();
            servicebuilder.AddConsumer();
            servicebuilder.AddRedisInitMqSetup();
            servicebuilder.AddStorage();
        }

        /// <summary>
        /// 添加配置
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="svp"></param>
        /// <param name="configuration"></param>
        public static void AddConfigureProvider(this IApplicationBuilder app, IWebHostEnvironment env,
            IServiceProvider svp, IConfiguration configuration, IServiceCollection services)
        {
            ICoreConfigurationBuilder configurationBuilder = new ConfigureBuilder(app, env, svp, configuration, services);
            configurationBuilder.UseNlog();
            configurationBuilder.UseSwagger();
            configurationBuilder.UseCors();
            configurationBuilder.UseRazorEngine();
            configurationBuilder.UseErrorHanle();
            configurationBuilder.UseAuth();
            configurationBuilder.UseOther();
        }
    }
}
